<?php
namespace Home\Controller;
use Think\Controller;
class ArticleController extends CommonController {

    /**
     * 文章分类
     */
    public function category(){
        $class = M('cms_article_class');
        $list = $class->select();
        if($list){
            returnApiSuccess('ok',$list);
        }
        returnArr('数据为空');

    }

    /**
     * 名车会文章列表
     */
	public function lists(){
        $article = M('cms_article');
        $pindex = I('post.pno',1,'intval') ;     //当前页码
        $psize  = I('post.pgz',10,'intval') ;   //显示条数

        if(!$pindex)  $pindex = 1;
        $pfirst = ($pindex - 1) * $psize;

        $cid = I('post.cid',0,'intval');
        if(!$cid)  returnApiError(1,'cid参数错误');
        $list = $article->field('article_id,article_author,article_title,article_class_id,article_abstract,article_click,article_share_count,article_image')->where("article_class_id=$cid and article_state = 3")->order(array('article_id'=>'desc'))->limit($pfirst .','.$psize)->select();
        foreach($list as $k=>$v){
            $img  = unserialize($list[$k]['article_image']);
            $list[$k]['article_image'] =  SHOP_SITE_URL.'/data/upload/cms/article/'.$img['path'].'/'.$img['name'];
        }
        if($list){
            returnApiSuccess('ok',$list);
        }
        returnArr('数据为空');

	}

    /**
     * 文章详情
     */
    public function detail(){
        $article_id = I('article_id',0,'intval');
        //$article_id = 1;
        if(!$article_id)  returnApiError(1,'article_id参数错误');
        $article = M('cms_article');
        $result = $article->where("article_id=$article_id")->find();
        if($result){
            $this->assign('list',$result);
            $this->display();
        }

    }

    /**
     * 帮助文档
     */
    public function help(){
        $article_id = I('article_id',0,'intval');
        //$article_id = 1;
        if(!$article_id)  returnApiError(1,'article_id参数错误');
        $article = M('article');
        $result = $article->where("article_id=$article_id")->find();
        if($result){
            $this->assign('list',$result);
            $this->display();
        }
    }

    /**
     * 名车会文章列表
     */
    public function recommend(){
        $article = M('cms_article');
        $pindex = I('post.pno',1,'intval') ;     //当前页码
        $psize  = I('post.pgz',10,'intval') ;   //显示条数

        if(!$pindex)  $pindex = 1;
        $pfirst = ($pindex - 1) * $psize;

        $list = $article->field('article_id,article_author,article_title,article_class_id,article_abstract,article_click,article_share_count,article_image')->where("article_commend_flag = 1  and article_state = 3")->order(array('article_id'=>'desc'))->limit($pfirst .','.$psize)->select();
        foreach($list as $k=>$v){
            $img  = unserialize($list[$k]['article_image']);
            $list[$k]['article_image'] =  SHOP_SITE_URL.'/data/upload/cms/article/'.$img['path'].'/'.$img['name'];
        }
        if($list){
            returnApiSuccess('ok',$list);
        }
        returnArr('数据为空');

    }

    /**
     * 系统文章
     */
    public function document(){
        $document_id = I('document_id',0,'intval');
        if(!$document_id) returnApiError(1,'请输入系统文章id');
        $document = M('document');
        $data = $document->find($document_id);
        $this->assign('list',$data);
        $this->display();

    }

    /**
     * 积分说明
     */
    public function pointsdes(){
        $setting = M('setting');
        $data = $setting->select();
        //登录送积分
        $points_login = $data[107]['value'];
        //注册送积分
        $points_reg = $data[111]['value'];
        //签到积分
        $points_signin = $data[112]['value'];
        //订单积分
        $points_orderrate = $data[109]['value'];
        //每订单最多赠送积分
        $points_ordermax = $data[108]['value'];
        //订单商品评论
        $points_comments = $data[104]['value'];


        $str = <<<eof
    1、登录送{$points_login}积分。
    2、注册送{$points_reg}积分。
    3、签到送{$points_signin}积分。
    4、订单消费额与赠送积分比例{$points_orderrate}%。
    5、每订单最多赠送积分{$points_ordermax}
    6、订单商品评论送{$points_comments}积分
eof;

        $this->assign('list',$str);
        $this->display();
    }




}